package com.hrt.datasender.datadao.service;

import java.util.List;

import com.btcode.orm.model.ModelPageResult;
import com.hrt.datasender.datadao.model.BcSiteModel;
import com.hrt.db.DBManager;

public final class BCSiteService {

    private static volatile BCSiteService instance;

    private BCSiteService() {

    }

    public static BCSiteService getInstance() {
        if (instance == null) {
            synchronized (BCSiteService.class) {
                if (instance == null) {
                    instance = new BCSiteService();
                }
            }
        }
        return instance;
    }

    public BcSiteModel getModel() {
        ModelPageResult mpr = DBManager.getORMExecuter().getModelList(BcSiteModel.class, null,null);
        List<BcSiteModel> models = mpr.getData();

        if (models == null) {
            return null;
        }

        if (models.size() > 0) {
            return models.get(0);
        }

        return null;
    }

    public void save(BcSiteModel model) {

        BcSiteModel vmodel = null;

        if (model.getId() != null) {
            vmodel = DBManager.getORMExecuter().getModel(model);
        }

        if (vmodel == null) {
            DBManager.getORMExecuter().create(model);
        }
        else {
            DBManager.getORMExecuter().update(model);
        }
    }
}
